<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="author" content="WD">





<title>C51单片机学习——密码锁的实现 | WD&#39;s blog</title>



    <link rel="icon" href="/favicon1.ico">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/js/script.js"></script>
    
    <script src="/js/tocbot.min.js"></script>
    
    <script src="/js/snow.js"></script>
    



    
    
        
    


<meta name="generator" content="Hexo 5.4.0"></head>
<body>
    <div class="wrapper">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo"><a href="/">WD&#39;s Blog</a></div>
            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
                <input id="switch_default" type="checkbox" class="switch_default">
                <label for="switch_default" class="toggleBtn"></label>
            </div>
        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/">WD&#39;s Blog</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
            </div>
        </div>
    </nav>

</header>
<script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>
        <div class="main">
            <div class="container">
    
    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">C51单片机学习——密码锁的实现</h1>
            
                <div class="post-meta">
                    
                        Author: <a itemprop="author" rel="author" href="/about/">WD</a>
                     &nbsp;

                    
                        <span class="post-time">
                        Date: <a href="#">June 13, 2019&nbsp;&nbsp;12:20:32</a>
                        </span>
                     &nbsp;
                    
                        <span class="post-category">
                    Category:
                            
                                <a href="/categories/C51%E5%8D%95%E7%89%87%E6%9C%BA/">C51单片机</a>
                            
                        </span>
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <br>
    <span id="busuanzi_container_site_pv">总阅读量:<a href="#"><span id="busuanzi_value_page_pv"></span></a>次</span>&nbsp;
    <span class="post-count">文章字数:<a href="#">2.6k</span></a>&nbsp;
     <span class="post-count">阅读时长:<a href="#">13</span>min</a>
                    
                </div>
            
        </header>

        <div class="post-content">
            <ul>
<li>说在前面：因为我的板子是液晶屏和数码管不能同时用，所以下面我使用的是液晶屏，下面的代码通俗易懂也有注释，如果有的控件不知到如何使用的可以查看我之前的几篇C51文章，这个密码锁就是基于之前的笔记所写的内容.</li>
</ul>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;reg52.h&gt;</span></span></span><br><span class="line"><span class="comment">//#include&lt;intrins.h&gt;</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> uint unsigned int</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> uchar unsigned char</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> data1602 P0</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> LED P2</span></span><br><span class="line"><span class="comment">/*******引脚定义*******/</span></span><br><span class="line"><span class="comment">//按键的控制引脚</span></span><br><span class="line">sbit S1 = P3^<span class="number">7</span>;</span><br><span class="line">sbit S2 = P3^<span class="number">6</span>;</span><br><span class="line">sbit S3 = P3^<span class="number">5</span>;</span><br><span class="line">sbit S4 = P3^<span class="number">4</span>;</span><br><span class="line">sbit S5 = P3^<span class="number">3</span>;</span><br><span class="line">sbit S6 = P3^<span class="number">2</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//LCD1602的控制引脚</span></span><br><span class="line">sbit RS = P1^<span class="number">0</span>;</span><br><span class="line">sbit RW = P1^<span class="number">1</span>;</span><br><span class="line">sbit E = P1^<span class="number">2</span>;</span><br><span class="line">sbit BF = data1602^<span class="number">7</span>; <span class="comment">//BF表示data1602的最高位，判断是忙还是闲</span></span><br><span class="line"></span><br><span class="line">sbit Alam = P1^<span class="number">5</span>;<span class="comment">//蜂鸣器引脚</span></span><br><span class="line"><span class="comment">//sbit key = P3^3;//开锁</span></span><br><span class="line"></span><br><span class="line">bit	 isInitPass = <span class="number">1</span>;<span class="comment">//是否在初始化密码</span></span><br><span class="line">bit  pass=<span class="number">0</span>;                   <span class="comment">//密码正确标志</span></span><br><span class="line">bit  isReset = <span class="number">0</span>;             <span class="comment">//是否在重设密码  </span></span><br><span class="line">uchar countNum = <span class="number">0</span>;	 <span class="comment">//选择数字位数</span></span><br><span class="line">uchar countPass = <span class="number">1</span>;<span class="comment">//输入密码位数</span></span><br><span class="line">uchar ErrorCont = <span class="number">0</span>;                    <span class="comment">//错误次数计数</span></span><br><span class="line">uchar timeNum=<span class="number">0</span>;		        <span class="comment">//计时间次数</span></span><br><span class="line">uchar trueTime=<span class="string">&#x27;5&#x27;</span>;		  <span class="comment">// 锁定时间                  </span></span><br><span class="line"><span class="comment">//液晶显示数据数组</span></span><br><span class="line">uchar code initLock1[] = &#123;<span class="string">&quot;   Welcome to   &quot;</span>&#125;;</span><br><span class="line">uchar code initLock2[] = &#123;<span class="string">&quot;  password lock &quot;</span>&#125;;</span><br><span class="line">uchar code SetNew[] = &#123;<span class="string">&quot;==SetPassword== &quot;</span>&#125;;</span><br><span class="line">uchar code Input[] = &#123;<span class="string">&quot;input:          &quot;</span>&#125;;  <span class="comment">//INPUT</span></span><br><span class="line">uchar code start_line1[] = &#123;<span class="string">&quot;==please input==&quot;</span>&#125;;</span><br><span class="line">uchar code start_line2[] = &#123;<span class="string">&quot;password:       &quot;</span>&#125;;</span><br><span class="line">uchar code superPassword[] = &#123;<span class="string">&quot;=Super Password=&quot;</span>&#125;;</span><br><span class="line">uchar code Correct[] = &#123;<span class="string">&quot;     correct    &quot;</span>&#125;;  <span class="comment">//输入正确</span></span><br><span class="line">uchar code Error[] = &#123;<span class="string">&quot;      error     &quot;</span>&#125;;    <span class="comment">//输入错误</span></span><br><span class="line">uchar code codepass[] = &#123;<span class="string">&quot;      pass      &quot;</span>&#125;; </span><br><span class="line">uchar code LockOpen[] = &#123;<span class="string">&quot;      open      &quot;</span>&#125;;   <span class="comment">//OPEN</span></span><br><span class="line">uchar code Reset[] = &#123;<span class="string">&quot;=ResetPassword= &quot;</span>&#125;;</span><br><span class="line">uchar code oldPassword[] = &#123;<span class="string">&quot;please input old&quot;</span>&#125;; <span class="comment">//输入旧密码</span></span><br><span class="line">uchar code setOK[] = &#123;<span class="string">&quot;Set Password OK &quot;</span>&#125;;</span><br><span class="line">uchar code <span class="literal">NULL</span>[] = &#123;<span class="string">&quot;                &quot;</span>&#125;;</span><br><span class="line">uchar code ResetOK[] = &#123;<span class="string">&quot;ResetPasswordOK!&quot;</span>&#125;;</span><br><span class="line">uchar code initword[] = &#123;<span class="string">&quot;Init password...&quot;</span>&#125;;</span><br><span class="line">uchar code ErrorTry[] = &#123;<span class="string">&quot;error,try again!&quot;</span>&#125;;</span><br><span class="line">uchar code again[] = &#123;<span class="string">&quot;input again     &quot;</span>&#125;;</span><br><span class="line">uchar code wait[] = &#123;<span class="string">&quot;please wait   s  &quot;</span>&#125;;</span><br><span class="line">uchar code table[]=&#123;<span class="number">0xfe</span>,<span class="number">0xfd</span>,<span class="number">0xfb</span>,<span class="number">0xf7</span>,<span class="number">0xef</span>,<span class="number">0xdf</span>,<span class="number">0xbf</span>,<span class="number">0x7f</span>&#125;;<span class="comment">//流水灯</span></span><br><span class="line"></span><br><span class="line">uchar InitPassword[<span class="number">6</span>]=&#123;<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>&#125;;       <span class="comment">//初始化密码暂存数组</span></span><br><span class="line">uchar CurrentPassword[<span class="number">6</span>]=&#123;<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;0&#x27;</span>&#125;;<span class="comment">//输入密码暂存数组</span></span><br><span class="line">uchar adminpassword[<span class="number">6</span>]=&#123;<span class="string">&#x27;1&#x27;</span>,<span class="string">&#x27;3&#x27;</span>,<span class="string">&#x27;1&#x27;</span>,<span class="string">&#x27;4&#x27;</span>,<span class="string">&#x27;2&#x27;</span>,<span class="string">&#x27;0&#x27;</span>&#125;;<span class="comment">//管理员密码</span></span><br><span class="line">uchar PassNum[<span class="number">10</span>] = &#123;<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;1&#x27;</span>,<span class="string">&#x27;2&#x27;</span>,<span class="string">&#x27;3&#x27;</span>,<span class="string">&#x27;4&#x27;</span>,<span class="string">&#x27;5&#x27;</span>,<span class="string">&#x27;6&#x27;</span>,<span class="string">&#x27;7&#x27;</span>,<span class="string">&#x27;8&#x27;</span>,<span class="string">&#x27;9&#x27;</span>&#125;;  <span class="comment">//存放所有数字</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*******延时函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">delay</span><span class="params">(uint z)</span><span class="comment">//z毫秒</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uint x,y;</span><br><span class="line">	<span class="keyword">for</span>(x=z;x&gt;<span class="number">0</span>;x--)</span><br><span class="line">		<span class="keyword">for</span>(y=<span class="number">110</span>;y&gt;<span class="number">0</span>;y--);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******空函数*******/</span></span><br><span class="line"><span class="comment">/*void Nop(void)                  //空操作</span></span><br><span class="line"><span class="comment">&#123;</span></span><br><span class="line"><span class="comment">	_nop_();                  //仅作延时用一条语句大约1us</span></span><br><span class="line"><span class="comment">    _nop_();</span></span><br><span class="line"><span class="comment">    _nop_();</span></span><br><span class="line"><span class="comment">    _nop_();</span></span><br><span class="line"><span class="comment">&#125;*/</span></span><br><span class="line"><span class="comment">/*******忙检测函数*******/</span></span><br><span class="line"><span class="function">bit <span class="title">LCD_busy</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	bit busy;</span><br><span class="line">	P0 = <span class="number">0xff</span>;<span class="comment">//防止干扰</span></span><br><span class="line">	RS = <span class="number">0</span>;	 <span class="comment">//命令模式</span></span><br><span class="line">	RW = <span class="number">1</span>;   <span class="comment">//读模式</span></span><br><span class="line">	E = <span class="number">1</span>;</span><br><span class="line">	busy = BF;<span class="comment">//将忙标志位的数值赋给busy</span></span><br><span class="line">	E = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">return</span> busy;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******写命令函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LCD_write_cmd</span><span class="params">(uchar cmd)</span><span class="comment">//cmd为需要写的命令</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">LCD_busy</span>());<span class="comment">//只有当LCD_busy()为0(闲)时才跳出循环   </span></span><br><span class="line">	RS = <span class="number">0</span>;		   <span class="comment">//命令模式</span></span><br><span class="line">	RW = <span class="number">0</span>;		   <span class="comment">//写模式</span></span><br><span class="line">	data1602 = cmd;	   <span class="comment">//将命令内容的十六进制送到P0端口</span></span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">1</span>);</span><br><span class="line">	E = <span class="number">1</span>;         <span class="comment">//拉高使能端，为制造有效的下降沿做准备</span></span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">1</span>);</span><br><span class="line">	E = <span class="number">0</span>;			<span class="comment">//由高变低，产生下降沿，液晶执行命令，使命令送到LCD1602的DB0~DB7</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******写数据函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LCD_write_data</span><span class="params">(uchar dat)</span><span class="comment">//dat为需要写的数据</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">LCD_busy</span>());<span class="comment">//只有当LCD_busy()为0(闲)时才跳出循环   </span></span><br><span class="line">	RS = <span class="number">1</span>;		   <span class="comment">//数据模式</span></span><br><span class="line">	RW = <span class="number">0</span>;		   <span class="comment">//写模式</span></span><br><span class="line">	data1602 = dat;	   <span class="comment">//将数据内容的十六进制送到P0端口</span></span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">1</span>);</span><br><span class="line">	E = <span class="number">1</span>;</span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">1</span>);</span><br><span class="line">	E = <span class="number">0</span>;			<span class="comment">//使能端，高电平有效，使命令送到LCD1602的DB0~DB7</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******IT0中断初始化函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">IT_init</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	IT0 = <span class="number">0</span>; <span class="comment">//设置低电平触发外部中断</span></span><br><span class="line">	EA = <span class="number">1</span>;  <span class="comment">//开总中断</span></span><br><span class="line">	EX0 = <span class="number">1</span>;<span class="comment">//开外部中断</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******定时器T0中断初始化函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Time_init</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	TMOD = <span class="number">0x01</span>;<span class="comment">//将定时器0设为方式1，即16位定时器</span></span><br><span class="line">	TH0 = (<span class="number">65536</span><span class="number">-45872</span>)/<span class="number">256</span>;<span class="comment">//给定时器的高八位赋初值</span></span><br><span class="line">	TL0 = (<span class="number">65536</span><span class="number">-45872</span>)%<span class="number">256</span>;<span class="comment">//给定时器的低八位赋初值</span></span><br><span class="line">	EA = <span class="number">1</span>;<span class="comment">//开总中断</span></span><br><span class="line">	ET0 = <span class="number">1</span>;<span class="comment">//开定时器0中断</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******LCD初始化函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LCD_init</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">LCD_write_cmd</span>(<span class="number">0x38</span>); <span class="comment">//将设置“两行、八位数据、5*7的点阵”命令写入LCD的控制器</span></span><br><span class="line">	<span class="built_in">LCD_write_cmd</span>(<span class="number">0x0c</span>); <span class="comment">//开显示关光标</span></span><br><span class="line">	<span class="built_in">LCD_write_cmd</span>(<span class="number">0x06</span>); <span class="comment">//光标右移指令</span></span><br><span class="line">	<span class="built_in">LCD_write_cmd</span>(<span class="number">0x01</span>); <span class="comment">//清除显示</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******LCD写显示地址函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LCD_write_address</span><span class="params">(uchar x,uchar y)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	x&amp;=<span class="number">0x0f</span>;  <span class="comment">//列地址限制在0~15之间</span></span><br><span class="line">	y&amp;=<span class="number">0x01</span>;  <span class="comment">//行地址限制在0~1</span></span><br><span class="line">	<span class="keyword">if</span>(y==<span class="number">0</span>)</span><br><span class="line">		<span class="built_in">LCD_write_cmd</span>(x|<span class="number">0x80</span>);<span class="comment">//数据指针=80+地址变量,写入列地址</span></span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">		<span class="built_in">LCD_write_cmd</span>((x+<span class="number">0x40</span>)|<span class="number">0x80</span>);	  <span class="comment">//如果是第二行，将列地址写入</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******LCD显示函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LCD_display</span><span class="params">(uchar x,uchar y,uchar buf)</span>	<span class="comment">//x：列 y：行，buf：显示的字符</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">LCD_write_address</span>(x,y);<span class="comment">//先将地址写入</span></span><br><span class="line">	<span class="built_in">LCD_write_data</span>(buf);	<span class="comment">//再写入要显示的数据</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*******一声提示音，表示有效输入*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">OneAlam</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	Alam=<span class="number">0</span>;	   <span class="comment">//蜂鸣器响</span></span><br><span class="line">    <span class="built_in">delay</span>(<span class="number">100</span>);  <span class="comment">//延时5ms</span></span><br><span class="line">   	Alam=<span class="number">1</span>;	   <span class="comment">//蜂鸣器关</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*******两声提示音，表示操作成功*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">TwoAlam</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uchar i = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">2</span>;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		Alam=<span class="number">0</span>;	   <span class="comment">//蜂鸣器响</span></span><br><span class="line">    	<span class="built_in">delay</span>(<span class="number">100</span>);  <span class="comment">//延时5ms</span></span><br><span class="line">   		Alam=<span class="number">1</span>;	   <span class="comment">//蜂鸣器关</span></span><br><span class="line">		<span class="built_in">delay</span>(<span class="number">100</span>);	</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*******三声提示音，表示错误*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">ThreeAlam</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uchar i = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">3</span>;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		Alam=<span class="number">0</span>;	   <span class="comment">//蜂鸣器响</span></span><br><span class="line">    	<span class="built_in">delay</span>(<span class="number">100</span>);  <span class="comment">//延时5ms</span></span><br><span class="line">   		Alam=<span class="number">1</span>;	   <span class="comment">//蜂鸣器关</span></span><br><span class="line">		<span class="built_in">delay</span>(<span class="number">100</span>);	</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******流水灯函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LED_display</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uint i;</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">8</span>;i++)   <span class="comment">//数组控制流水灯</span></span><br><span class="line">	&#123;</span><br><span class="line">		LED = table[i];</span><br><span class="line">		<span class="built_in">delay</span>(<span class="number">500</span>);</span><br><span class="line">	&#125;</span><br><span class="line">	LED = <span class="number">0x00</span>;</span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">1000</span>);</span><br><span class="line">	LED = <span class="number">0xff</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*******初始化界面函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init_display</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uchar i;</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,initLock1[i]);</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,initLock2[i]);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******按键控制输入密码函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">pushBtn_password</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	countNum = <span class="number">0</span>;</span><br><span class="line">	countPass = <span class="number">1</span>;</span><br><span class="line">	<span class="built_in">LCD_write_cmd</span>(<span class="number">0x0e</span>); <span class="comment">//光标闪烁</span></span><br><span class="line">	<span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span>(S1 == <span class="number">0</span>)     <span class="comment">//第一次检测按键被按下</span></span><br><span class="line">		&#123;</span><br><span class="line">			<span class="built_in">delay</span>(<span class="number">8</span>);   <span class="comment">//延时8ms进行消抖</span></span><br><span class="line">			<span class="keyword">if</span>(S1 == <span class="number">0</span>)	  <span class="comment">//再次检测按键被按下，说明确实被按下了</span></span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(isInitPass)</span><br><span class="line">					<span class="built_in">LCD_display</span>(<span class="number">6</span>+countPass,<span class="number">1</span>,PassNum[countNum]); <span class="comment">//显示数字</span></span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">					<span class="built_in">LCD_display</span>(<span class="number">9</span>+countPass,<span class="number">1</span>,PassNum[countNum]);			</span><br><span class="line">				<span class="built_in">LCD_write_cmd</span>(<span class="number">0x10</span>);	<span class="comment">//光标左移</span></span><br><span class="line">				<span class="keyword">if</span>(isInitPass)</span><br><span class="line">					InitPassword[countPass<span class="number">-1</span>] = PassNum[countNum]; <span class="comment">//将输入的数字存到初始化数组中</span></span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">					CurrentPassword[countPass<span class="number">-1</span>] = PassNum[countNum];<span class="comment">//将输入的数字存到当前数组中</span></span><br><span class="line"></span><br><span class="line">				<span class="keyword">if</span>(countNum == <span class="number">9</span>)</span><br><span class="line">					countNum = <span class="number">0</span>;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">					countNum++;			</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">delay</span>(<span class="number">300</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(S3 == <span class="number">0</span>)     <span class="comment">//第一次检测按键被按下</span></span><br><span class="line">		&#123;</span><br><span class="line">			<span class="built_in">delay</span>(<span class="number">8</span>);   <span class="comment">//延时8ms进行消抖</span></span><br><span class="line">			<span class="keyword">if</span>(S3 == <span class="number">0</span>)	  <span class="comment">//再次检测按键被按下，说明确实被按下了</span></span><br><span class="line">			&#123;</span><br><span class="line">				countNum = <span class="number">0</span>;</span><br><span class="line">				<span class="keyword">if</span>(countPass == <span class="number">6</span>)</span><br><span class="line">					countPass = <span class="number">1</span>;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">					countPass++;</span><br><span class="line">				<span class="keyword">if</span>(isInitPass)</span><br><span class="line">					<span class="built_in">LCD_display</span>(<span class="number">6</span>+countPass,<span class="number">1</span>,InitPassword[countPass<span class="number">-1</span>]); </span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">					<span class="built_in">LCD_display</span>(<span class="number">9</span>+countPass,<span class="number">1</span>,CurrentPassword[countPass<span class="number">-1</span>]);	</span><br><span class="line">				<span class="built_in">LCD_write_cmd</span>(<span class="number">0x10</span>);			</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">delay</span>(<span class="number">250</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(S4 == <span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="built_in">delay</span>(<span class="number">8</span>);   <span class="comment">//延时8ms进行消抖</span></span><br><span class="line">			<span class="keyword">if</span>(S4 == <span class="number">0</span>)	  <span class="comment">//再次检测按键被按下，说明确实被按下了</span></span><br><span class="line">			&#123;</span><br><span class="line">				countNum = <span class="number">0</span>;</span><br><span class="line">				<span class="keyword">if</span>(countPass&gt;<span class="number">1</span>)</span><br><span class="line">					countPass--;</span><br><span class="line">				<span class="keyword">else</span></span><br><span class="line">					countPass = <span class="number">1</span>;</span><br><span class="line">	   		&#125;</span><br><span class="line">			<span class="keyword">if</span>(isInitPass)</span><br><span class="line">				<span class="built_in">LCD_display</span>(<span class="number">6</span>+countPass,<span class="number">1</span>,InitPassword[countPass<span class="number">-1</span>]); </span><br><span class="line">			<span class="keyword">else</span></span><br><span class="line">				<span class="built_in">LCD_display</span>(<span class="number">9</span>+countPass,<span class="number">1</span>,CurrentPassword[countPass<span class="number">-1</span>]);			</span><br><span class="line">			<span class="built_in">LCD_write_cmd</span>(<span class="number">0x10</span>);</span><br><span class="line">			<span class="built_in">delay</span>(<span class="number">300</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(S5 == <span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="built_in">delay</span>(<span class="number">8</span>);</span><br><span class="line">			<span class="keyword">if</span>(S5 == <span class="number">0</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">LCD_write_cmd</span>(<span class="number">0x0c</span>); <span class="comment">//光标不闪烁	</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*******最初设置密码函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init_password</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uchar i = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,SetNew[i]);</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,Input[i]);</span><br><span class="line">	<span class="built_in">pushBtn_password</span>();    <span class="comment">//按键控制输入密码</span></span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,<span class="literal">NULL</span>[i]);</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,<span class="literal">NULL</span>[i]);</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">13</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,initword[i]);</span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">500</span>);</span><br><span class="line">	<span class="built_in">LCD_display</span>(<span class="number">13</span>,<span class="number">0</span>,initword[<span class="number">13</span>]);<span class="comment">//滚动显示初始化中</span></span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">500</span>);</span><br><span class="line">	<span class="built_in">LCD_display</span>(<span class="number">14</span>,<span class="number">0</span>,initword[<span class="number">14</span>]);</span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">500</span>);</span><br><span class="line">	<span class="built_in">LCD_display</span>(<span class="number">15</span>,<span class="number">0</span>,initword[<span class="number">15</span>]);</span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">500</span>);</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,setOK[i]);</span><br><span class="line">	<span class="built_in">TwoAlam</span>();<span class="comment">//两声提示音，表示操作成功</span></span><br><span class="line">	isInitPass = <span class="number">0</span>; 		</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******判断是否输入正确函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">judge</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uchar jg = <span class="number">0</span>;</span><br><span class="line">	uchar i;</span><br><span class="line">	<span class="keyword">if</span>((CurrentPassword[<span class="number">0</span>]==InitPassword[<span class="number">0</span>])&amp;&amp;(CurrentPassword[<span class="number">1</span>]==InitPassword[<span class="number">1</span>])&amp;&amp;(CurrentPassword[<span class="number">2</span>]==InitPassword[<span class="number">2</span>])&amp;&amp;(CurrentPassword[<span class="number">3</span>]==InitPassword[<span class="number">3</span>])&amp;&amp;(CurrentPassword[<span class="number">4</span>]==InitPassword[<span class="number">4</span>])&amp;&amp;(CurrentPassword[<span class="number">5</span>]==InitPassword[<span class="number">5</span>]))</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span>(isReset==<span class="number">0</span>)</span><br><span class="line">			jg = <span class="number">1</span>;	<span class="comment">//正确输入密码</span></span><br><span class="line">		<span class="keyword">else</span></span><br><span class="line">			jg = <span class="number">3</span>;	<span class="comment">//正确输入密码且在重设密码</span></span><br><span class="line">		pass = <span class="number">1</span>;   <span class="comment">//密码正确</span></span><br><span class="line">	&#125;	</span><br><span class="line">	<span class="keyword">else</span> <span class="keyword">if</span>((CurrentPassword[<span class="number">0</span>]==adminpassword[<span class="number">0</span>])&amp;&amp;(CurrentPassword[<span class="number">1</span>]==adminpassword[<span class="number">1</span>])&amp;&amp;(CurrentPassword[<span class="number">2</span>]==adminpassword[<span class="number">2</span>])&amp;&amp;(CurrentPassword[<span class="number">3</span>]==adminpassword[<span class="number">3</span>])&amp;&amp;(CurrentPassword[<span class="number">4</span>]==adminpassword[<span class="number">4</span>])&amp;&amp;(CurrentPassword[<span class="number">5</span>]==adminpassword[<span class="number">5</span>]))</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span>(isReset==<span class="number">0</span>)</span><br><span class="line">			jg = <span class="number">2</span>;	<span class="comment">//正确输入管理员超级密码</span></span><br><span class="line">		<span class="keyword">else</span></span><br><span class="line">			jg = <span class="number">4</span>;	<span class="comment">//正确输入管理员超级密码且在重设密码</span></span><br><span class="line">		pass = <span class="number">1</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">		ErrorCont++;  <span class="comment">//错误次数+1</span></span><br><span class="line">			</span><br><span class="line">	<span class="keyword">if</span>(jg==<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,Correct[i]);</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,LockOpen[i]);</span><br><span class="line">		<span class="built_in">OneAlam</span>();</span><br><span class="line">		<span class="built_in">LED_display</span>();</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span> <span class="keyword">if</span>(jg==<span class="number">2</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)  </span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,superPassword[i]);</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,LockOpen[i]);</span><br><span class="line">		<span class="built_in">OneAlam</span>();</span><br><span class="line">		<span class="built_in">LED_display</span>();</span><br><span class="line">	&#125;<span class="keyword">else</span> <span class="keyword">if</span>(jg==<span class="number">3</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,Correct[i]);</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,<span class="literal">NULL</span>[i]);</span><br><span class="line">		<span class="built_in">OneAlam</span>();</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span> <span class="keyword">if</span>(jg==<span class="number">4</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)  </span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,superPassword[i]);</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,<span class="literal">NULL</span>[i]);</span><br><span class="line">		<span class="built_in">OneAlam</span>();</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)  </span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,ErrorTry[i]);</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">			<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,<span class="literal">NULL</span>[i]);</span><br><span class="line">		<span class="built_in">ThreeAlam</span>();</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*******显示输入密码函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">input_Password</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uchar i;</span><br><span class="line">	<span class="keyword">do</span>&#123;</span><br><span class="line">		<span class="keyword">if</span>(ErrorCont==<span class="number">3</span>)</span><br><span class="line">		&#123;	</span><br><span class="line">			TR0 = <span class="number">1</span>;    <span class="comment">//启动定时器T0 </span></span><br><span class="line">			ErrorCont = <span class="number">0</span>;</span><br><span class="line">			<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">				<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,wait[i]);</span><br><span class="line">			<span class="built_in">LCD_display</span>(<span class="number">12</span>,<span class="number">0</span>,trueTime);</span><br><span class="line">			<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">				<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,again[i]);</span><br><span class="line">			</span><br><span class="line">			<span class="keyword">while</span>(trueTime &gt;= <span class="number">48</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="keyword">if</span>(timeNum == <span class="number">20</span>) <span class="comment">//num=20代表用了50ms*20  = 1s</span></span><br><span class="line">				&#123;</span><br><span class="line">					timeNum = <span class="number">0</span>;</span><br><span class="line">					trueTime--;  <span class="comment">//锁定时间减1</span></span><br><span class="line">					<span class="built_in">LCD_display</span>(<span class="number">12</span>,<span class="number">0</span>,trueTime);</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">			TR0 = <span class="number">0</span>;    <span class="comment">//关闭定时器T0</span></span><br><span class="line">			trueTime = <span class="string">&#x27;5&#x27;</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,start_line1[i]);</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,start_line2[i]);	</span><br><span class="line">		<span class="built_in">pushBtn_password</span>();</span><br><span class="line">		<span class="built_in">judge</span>();</span><br><span class="line">	&#125;<span class="keyword">while</span>(pass==<span class="number">0</span>);</span><br><span class="line">		</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*******main函数*******/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123; </span><br><span class="line">	<span class="built_in">LCD_init</span>();</span><br><span class="line">	<span class="built_in">IT_init</span>();</span><br><span class="line">	<span class="built_in">Time_init</span>();</span><br><span class="line">	<span class="built_in">init_display</span>();</span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">2000</span>);</span><br><span class="line">	<span class="built_in">init_password</span>();</span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">2000</span>);</span><br><span class="line">	<span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">input_Password</span>();</span><br><span class="line">		<span class="built_in">delay</span>(<span class="number">1000</span>);</span><br><span class="line">	&#125;</span><br><span class="line">			</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">reSetPassword</span><span class="params">()</span> interrupt 0</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	uchar i;</span><br><span class="line">	isReset = <span class="number">1</span>;</span><br><span class="line">	isInitPass = <span class="number">0</span>; </span><br><span class="line"></span><br><span class="line">	<span class="keyword">do</span>&#123;</span><br><span class="line">		<span class="comment">/*if(ErrorCont==3)</span></span><br><span class="line"><span class="comment">		&#123;	</span></span><br><span class="line"><span class="comment">			TR0 = 1;    //启动定时器T0 </span></span><br><span class="line"><span class="comment">			ErrorCont = 0;</span></span><br><span class="line"><span class="comment">			for(i=0;i&lt;16;i++)</span></span><br><span class="line"><span class="comment">				LCD_display(i,0,wait[i]);</span></span><br><span class="line"><span class="comment">			LCD_display(12,0,trueTime);</span></span><br><span class="line"><span class="comment">			for(i=0;i&lt;16;i++)</span></span><br><span class="line"><span class="comment">				LCD_display(i,1,again[i]);</span></span><br><span class="line"><span class="comment">			</span></span><br><span class="line"><span class="comment">			while(trueTime &gt;= 48)</span></span><br><span class="line"><span class="comment">			&#123;</span></span><br><span class="line"><span class="comment">				if(timeNum == 20) //num=20代表用了50ms*20  = 1s</span></span><br><span class="line"><span class="comment">				&#123;</span></span><br><span class="line"><span class="comment">					timeNum = 0;</span></span><br><span class="line"><span class="comment">					trueTime--;  //锁定时间减1</span></span><br><span class="line"><span class="comment">					LCD_display(12,0,trueTime);</span></span><br><span class="line"><span class="comment">				&#125;</span></span><br><span class="line"><span class="comment">			&#125;</span></span><br><span class="line"><span class="comment">			TR0 = 0;    //关闭定时器T0</span></span><br><span class="line"><span class="comment">			trueTime = &#x27;5&#x27;;</span></span><br><span class="line"><span class="comment">		&#125;*/</span></span><br><span class="line">		<span class="keyword">if</span>(ErrorCont==<span class="number">3</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,oldPassword[i]);</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,start_line2[i]);	</span><br><span class="line">		<span class="built_in">pushBtn_password</span>();</span><br><span class="line">		<span class="built_in">judge</span>();</span><br><span class="line">	&#125;<span class="keyword">while</span>(pass==<span class="number">0</span>&amp;&amp;ErrorCont&lt;<span class="number">3</span>);</span><br><span class="line"></span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">1000</span>);</span><br><span class="line">	<span class="keyword">if</span>(pass == <span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)	 </span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,Reset[i]);</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,Input[i]);</span><br><span class="line">	isInitPass = <span class="number">1</span>;</span><br><span class="line">	<span class="built_in">pushBtn_password</span>();    <span class="comment">//按键控制输入密码</span></span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)  </span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,ResetOK[i]);</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">		<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,<span class="literal">NULL</span>[i]);</span><br><span class="line">	<span class="built_in">TwoAlam</span>();</span><br><span class="line">	<span class="built_in">delay</span>(<span class="number">1000</span>);		</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">	<span class="built_in">LCD_display</span>(i,<span class="number">0</span>,start_line1[i]);</span><br><span class="line">	<span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;<span class="number">16</span>;i++)</span><br><span class="line">	<span class="built_in">LCD_display</span>(i,<span class="number">1</span>,start_line2[i]);</span><br><span class="line">	isInitPass = <span class="number">0</span>;</span><br><span class="line">	isReset = <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">TimeCount</span><span class="params">()</span> interrupt 1</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	TH0 = (<span class="number">65536</span><span class="number">-45872</span>)/<span class="number">256</span>;<span class="comment">//重装初值</span></span><br><span class="line">	TL0 = (<span class="number">65536</span><span class="number">-45872</span>)%<span class="number">256</span>;</span><br><span class="line">	timeNum++;			  <span class="comment">//每发生一次中断后，num++</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
        </div>

        
            <section class="post-copyright">
                
                    <p class="copyright-item">
                        <span>Author:</span>
                        <span><a href="/about/">WD</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>Permalink:</span>
                        <span><a href="https://did321.gitee.io/2019/06/13/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E5%AF%86%E7%A0%81%E9%94%81%E7%9A%84%E5%AE%9E%E7%8E%B0/">https://did321.gitee.io/2019/06/13/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E5%AF%86%E7%A0%81%E9%94%81%E7%9A%84%E5%AE%9E%E7%8E%B0/</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>License:</span>
                        <span>Copyright (c) 2022 <a target="_blank" rel="noopener" href="http://creativecommons.org/licenses/by-nc/4.0/">CC-BY-NC-4.0</a> LICENSE</span>
                    </p>
                
                
                     <p class="copyright-item">
                         <span>Slogan:</span>
                         <span><a href="#">The blog is my giant.</a></span>
                     </p>
                

            </section>
        
        <section class="post-tags">
            <div>
                <span>Tag(s):</span>
                <span class="tag">
                    
                    
                        <a href="/tags/C51%E5%8D%95%E7%89%87%E6%9C%BA/"># C51单片机</a>
                    
                        
                </span>
            </div>
            <div>
                <a href="javascript:window.history.back();">back</a>
                <span>· </span>
                <a href="/">home</a>
            </div>
        </section>
        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/2019/06/15/Mysql%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-%E4%B8%89-%E2%80%94%E2%80%94%E5%8D%95%E8%A1%A8%E6%9F%A5%E8%AF%A2/">Mysql学习笔记(三)——单表查询</a>
            
            
            <a class="next" rel="next" href="/2019/06/13/Mysql%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-%E4%BA%8C-%E2%80%94%E2%80%94%E8%A1%A8%E6%A0%BC%E5%8F%8A%E6%95%B0%E6%8D%AE%E7%9A%84%E6%8F%92%E5%85%A5/">Mysql学习笔记(二)——表格及数据的插入</a>
            
        </section>
        <br>
        <br>
    
    <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
    <div id="vcomments"></div>
    <script>
        new Valine({
    el: '#vcomments' ,

    appId: 'JvFy3ebVLo2rUYgHaMweJyXX-MdYXbMMI',
    appKey: 'TCFxfjDAM8UmERPEgYXJmT40',
    serverURLs: 'https://JvFy3ebV.api.lncldglobal.com', 
    placeholder: '----评论区----留下你的评论，作者会定期回复！在昵称处填写QQ号可自动获取邮箱和QQ头像（保护QQ邮箱隐私）',
    enableQQ: true,
    requiredFields: ['nick'],
});
    </script>

    </article>
</div>

        </div>
        <footer id="footer" class="footer">
    <div class="copyright">
        <span>© WD | Powered by <a href="https://hexo.io" target="_blank">Hexo</a> & <a href="https://github.com/Siricee/hexo-theme-Chic" target="_blank">Chic</a></span>
    </div>
</footer>

    </div>
</body>

</html>
